//
//  HJMainViewController.swift
//  WeiBo
//
//  Created by 韩俊 on 15/12/5.
//  Copyright © 2015年 HanJun. All rights reserved.
//

import UIKit
import SVProgressHUD

class HJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let tabBar = HJTabBar()
        
        tabBar.composeButtonClosure = {
            
            if !HJUserAccountViewModel.sharedAccount.userLogon {
                SVProgressHUD.showErrorWithStatus("请先登录")
                return
            }
            let composeView = HJComposeView()

            composeView.show(self)
        }
        setValue(tabBar, forKeyPath: "tabBar")

        view.backgroundColor = UIColor.whiteColor()
        
        
        addChildViewController(HJHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(HJMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(HJDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(HJProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    
    
    
    //添加子控制器
    func addChildViewController(childController: UIViewController, imageName:String, title:String) {
        
        childController.tabBarItem = HJTabBarItem()
        //设置文字
//        childController.navigationItem.title = title
//        childController.tabBarItem.title = title
        childController.title = title
        //字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //用图片的原样显示 imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        
        addChildViewController(HJNavigationController(rootViewController: childController))
    }
    
    
    
}
